<template>
    <div>
        房型名称<input type="text" v-model="que.fxmc">
     状态:   <input type="radio" name="1" v-model="que.zt" value="true" >启用
        <input type="radio" name="1"  v-model="que.zt" value="false" >停用
        <input type="button" value="查询" @click="xs">
        <input type="button" value="重置" @click="cz">
        

        <table class="table">
            <thead>
                <tr>
                    <td>序号</td>
                    <td>房型名称</td>
                    <td>门市销售价格</td>
                    <td>房间数</td>
                    <td>状态</td>
                    <td>房间号</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="m in data">
                    <td>{{m.id}}</td>
                    <td>{{m.fxmc}}</td>
                    <td>￥{{m.jg}}</td>
                    <td>{{m.fjs}}</td>
                    <td>{{m.zt?"启用":"停用"}}</td>
                    <td>{{m.fjh}}</td>
                    <td>
                        <input type="button" value="删除" @click="sc(m.id)">
                        <input type="button" value="编辑" @click="xgg(m.id)">
                    </td>
                </tr>
            </tbody>
        </table>
        总记录数{{quer.count}}总页数{{quer.plist}}当前页{{que.index}}
        <input type="button" value="首页" @click="page(1)">
        <input type="button" value="上一页" @click="page(2)">
        <input type="button"  v-for="w in sert" :value="w"@click="page(5)">
        <input type="button" value="下一页" @click="page(3)">
        <input type="button" value="尾页" @click="page(4)">
        跳转<input type="number" v-model="sertt">页
        <input type="button" value="跳转" @click="page(6)">
        

        
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';

const stre = useRouter();



const data=ref([{
    "id": 0,
  "fxmc": "string",
  "jg": 0,
  "fjs": 0,
  "zt": true,
  "fjh": "string",
  "sc": true
}])

const sert = ref([1,2,3,4])
const sertt = ref()

const page=(w:any)=>{
    if(w==1){
        que.value.index=1;
        xs();
    }
    if(w==2){
        if(que.value.index>1){
            que.value.index-=1;
            xs();
        }
        
    }
 
    if(w==6){
        que.value.index=sertt.value
        xs();

    }
    if(w==5){
        que.value.index=2
        xs();

    }
    if(w==3){
        if(que.value.index<quer.value.plist){
            que.value.index+=1;
            xs();
        }
     
    }
    if(w==4){
        que.value.index=quer.value.plist;
        xs();
    }
}
const que = ref({
    index:1,
    page:2,
    fxmc:"",
    zt:null
})
const cz=()=>{
   
  que.value.fxmc="",
   que.value.zt=null
   xs();
}
const quer = ref({
    count:0,
    plist:0,
})
onMounted(()=>{
    xs();
})
const xs=()=>{
    
    axios.get("https://localhost:7029/api/we/xs",{params:que.value}).then(res=>{
        data.value=res.data.plist

        quer.value.count =res.data.count;
        quer.value.plist= Math.ceil(quer.value.count/que.value.page);
    })
}
const sc=(w:any)=>{
    if(!confirm("确认删除吗")){
        return
    }
    axios.delete("https://localhost:7029/api/we/delete",{params:{id:w}}).then(res=>{
        if(res.data>0){
            alert("删除成功");
            xs();
        }else{
            alert("删除失败")
        }
    })
}
const  xgg=(a:any)=>{
    stre.push({path:"/xg",query:{id:a}})
}

</script>

<style scoped>

</style>